NET Email Validation
ValidateListAsync(List<String>) Method
Example 






KellermanSoftware.NetEmailValidation Namespace > EmailValidation Class > ValidateListAsync Method : ValidateListAsync(List<String>) Method
Validate a list of emails asynchronously using default options
Syntax
'Declaration
 
Public Overloads Sub ValidateListAsync( _
   ByVal emailAddresses As System.Collections.Generic.List(Of String) _
) 
'Usage
 
Dim instance As EmailValidation
Dim emailAddresses As System.Collections.Generic.List(Of String)
 
instance.ValidateListAsync(emailAddresses)
public void ValidateListAsync( 
   System.Collections.Generic.List<string> emailAddresses
)
public procedure ValidateListAsync( 
    emailAddresses: System.Collections.Generic.List
); 
public function ValidateListAsync( 
   emailAddresses : System.Collections.Generic.List
);
public: void ValidateListAsync( 
   System.Collections.Generic.List<string*>* emailAddresses
) 
public:
void ValidateListAsync( 
   System.Collections.Generic.List<String^>^ emailAddresses
) 

Parameters

emailAddresses
Example
public void Example()
{
    EmailValidation emailValidator = new EmailValidation(); //Trial Mode
    //EmailValidation emailValidator = new EmailValidation("place user name here", "place license key here"); //License Mode
 
    emailValidator.FromEmail = "someone@somewhere.com";
    emailValidator.FromMailServer = "mail.somewhere.com";
 
    //Create a list of 100 email addresses
    List<string> emailAddresses = new List<string>();
 
    for (int i = 1; i <= 100; i++)
        emailAddresses.Add(string.Format("johnsmith{0}@hotmail.com", i));
 
    //Attach Events                
    emailValidator.ProgressEvent += new EmailValidation.ProgressChangedEventHandler(ProgressEvent);
    emailValidator.ValidationCompleteEvent += new AsyncCompletedEventHandler(CompletionEvent);
    emailValidator.ResponseReceivedEvent += new EmailValidation.ResponseReceivedEventHandler(ResponseReceivedEvent);
 
    //Begin asynchronous validation
    emailValidator.ValidateListAsync(emailAddresses);
 
    while (emailValidator.IsBusy)
    {
        //Sleep 1 second
        System.Threading.Thread.Sleep(1000);
    }
 
    //Remove the event connections
    emailValidator.ProgressEvent -= new EmailValidation.ProgressChangedEventHandler(ProgressEvent);
    emailValidator.ValidationCompleteEvent -= new AsyncCompletedEventHandler(CompletionEvent);
    emailValidator.ResponseReceivedEvent -= new EmailValidation.ResponseReceivedEventHandler(ResponseReceivedEvent);   
}
 
 
public void CompletionEvent(object sender, AsyncCompletedEventArgs e)
{
    Console.WriteLine("Finished. Validated emails");
}
 
public void ProgressEvent(object sender, ProgressEventArgs args)
{
    Console.WriteLine(string.Format("{0}% ({1} of {2}", args.ProgressPercentage, args.EmailsProcessed, args.TotalEmailsToProcess));
}
 
public void ResponseReceivedEvent(object sender, Result result)
{
    if (result.IsValid)
    {
        //Do something
    }
    else
    {
        //Do something else
    }
 
    Console.WriteLine(result.Log);
}
Public Sub Example()
    Dim emailValidator As EmailValidation = New EmailValidation() 'Trial Mode
    'Dim emailValidator As EmailValidation = New EmailValidation("place user name here", "place license key here") 'License Mode
 
    emailValidator.FromEmail = "someone@somewhere.com"
    emailValidator.FromMailServer = "mail.somewhere.com"
 
    'Create a list of 100 email addresses
    Dim emailAddresses As List(Of String) = New List(Of String)()
 
    For i As Integer = 1 To 100
        emailAddresses.Add(String.Format("johnsmith{0}@hotmail.com", i))
    Next i
 
    'Attach Events                
    AddHandler emailValidator.ProgressEvent, AddressOf ProgressEvent
    AddHandler emailValidator.ValidationCompleteEvent, AddressOf CompletionEvent
    AddHandler emailValidator.ResponseReceivedEvent, AddressOf ResponseReceivedEvent
 
    'Begin asynchronous validation
    emailValidator.ValidateListAsync(emailAddresses)
 
    Do While emailValidator.IsBusy
        'Sleep 1 second
        System.Threading.Thread.Sleep(1000)
    Loop
 
    'Remove the event connections
    RemoveHandler emailValidator.ProgressEvent, AddressOf ProgressEvent
    RemoveHandler emailValidator.ValidationCompleteEvent, AddressOf CompletionEvent
    RemoveHandler emailValidator.ResponseReceivedEvent, AddressOf ResponseReceivedEvent
    
End Sub
    
 
Public Sub CompletionEvent(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
    Console.WriteLine("Finished. Validated emails")
End Sub
 
Public Sub ProgressEvent(ByVal sender As Object, ByVal args As ProgressEventArgs)
    Console.WriteLine(String.Format("{0}% ({1} of {2}", args.ProgressPercentage, args.EmailsProcessed, args.TotalEmailsToProcess))
End Sub
 
Public Sub ResponseReceivedEvent(ByVal sender As Object, ByVal result As Result)
    If result.IsValid Then
        'Do something
    Else
        'Do something else
    End If
 
    Console.WriteLine(result.Log)
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EmailValidation Class
EmailValidation Members
Overload List